home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1840 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.1 KB

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: weatby@aol.com (Weatby)
  3. Newsgroups: comp.lang.c++
  4. Subject: Destructors in functions
  5. Date: 13 Jan 1996 03:40:37 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4d7r65$dv9@newsbf02.news.aol.com>
  9. Reply-To: weatby@aol.com (Weatby)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. If you pass an object to a function, the language makes a bitwise copy of
  13. it, local to the function.  (Assuming no copy constructor is defined.) 
  14. Then, on the way out, the function calls the user-defined constructor.
  15.  
  16. This will cause problems if the object has any pointers in it (if they are
  17. released by the destructor, as they 'should' be).
  18.  
  19. The question is, why call a destructor on an object for which no
  20. constructor was called?  The compiler has probably put the local copy on
  21. its stack, and could pop it off on the way out.
  22.  
  23. Calling a destructor, automatically, for which no constructor was called
  24. seems to be a non-useful feature.  Does anyone know why this was included
  25. in the language definition?
  26.  
  27. Thanks.
  28.  
  29. Bob
  30.